#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3f;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int> a;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a.push_back(min(x % k, abs(x % k - k)));
	}
	vector<int> b;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		b.push_back(min(x % k, abs(x % k - k)));
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	cout << (a == b ? "Yes" : "No") << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}